<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>求阶乘之和</title>
</head>
<body>
    <script>
        
        // 总和
        var total = 0;

        //  内层相乘，外层相加
        for(var j=1;j<=20;j++){
            //重置阶乘基础，使得每个单独阶乘的基础值为1
            var jc = 1;
            //各阶乘
            for(i=1;i<=j;i++){
                jc *= i;
            }
            console.log(j+'阶乘为：',jc);
            //阶乘相加
            total += jc;
        }

        console.log((j-1)+'阶乘和为：',total);
            
        /* 
        var sum = 0;
        var jc = 1;
        for(var n = 1;n<=20; n++){
            jc *= n;
            console.log("JC结果：",jc)
            sum +=jc;
        }
        console.log(sum) 
        */

    </script>
</body>
</html>